package com.runa.monitor.platinterface.extend.third.newester.validator;

import org.springframework.util.StringUtils;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.Arrays;
import java.util.List;

/**
 * @Author: lyd
 * @Description:
 * @Date: 2021/11/3 10:18
 * @Version: 1.0
 */
public class EnumValidator implements ConstraintValidator<Enum,String> {
    private List<String> valueList ;
    @Override
    public void initialize(Enum constraintAnnotation) {
        String[] value = constraintAnnotation.value();
        this.valueList = Arrays.asList(value);
    }

    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
        if (StringUtils.isEmpty(value)) {
            return true;
        }
        return this.valueList.contains(value);
    }
}